/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author dingnangen
 */
@Entity
@Table(name = "resource")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Resource.findAll", query = "SELECT r FROM Resource r"),
    @NamedQuery(name = "Resource.findByIdresource", query = "SELECT r FROM Resource r WHERE r.idresource = :idresource"),
    @NamedQuery(name = "Resource.findByNodename", query = "SELECT r FROM Resource r WHERE r.nodename = :nodename"),
    @NamedQuery(name = "Resource.findByPermissions", query = "SELECT r FROM Resource r WHERE r.permissions = :permissions"),
    @NamedQuery(name = "Resource.findByParentNodeId", query = "SELECT r FROM Resource r WHERE r.parentNodeId = :parentNodeId"),
    @NamedQuery(name = "Resource.findByNodeUrl", query = "SELECT r FROM Resource r WHERE r.nodeUrl = :nodeUrl"),
    @NamedQuery(name = "Resource.findByNodeType", query = "SELECT r FROM Resource r WHERE r.nodeType = :nodeType"),
    @NamedQuery(name = "Resource.findByNodeDepth", query = "SELECT r FROM Resource r WHERE r.nodeDepth = :nodeDepth"),
    @NamedQuery(name = "Resource.findByResourceorder", query = "SELECT r FROM Resource r WHERE r.resourceorder = :resourceorder"),
    @NamedQuery(name = "Resource.findByAvailable", query = "SELECT r FROM Resource r WHERE r.available = :available")})
public class Resource implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idresource")
    private Integer idresource;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "nodename")
    private String nodename;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 15)
    @Column(name = "permissions")
    private String permissions;
    @Column(name = "parent_node_id")
    private Integer parentNodeId;
    @Size(max = 200)
    @Column(name = "node_url")
    private String nodeUrl;
    @Column(name = "node_type")
    private Integer nodeType;
    @Basic(optional = false)
    @NotNull
    @Column(name = "node_depth")
    private int nodeDepth;
    @Column(name = "resourceorder")
    private Integer resourceorder;
    @Basic(optional = false)
    @NotNull
    @Column(name = "available")
    private boolean available;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idresource")
    private List<RoleResource> roleResourceList;

    public Resource() {
    }

    public Resource(Integer idresource) {
        this.idresource = idresource;
    }

    public Resource(Integer idresource, String nodename, String permissions, int nodeDepth, boolean available) {
        this.idresource = idresource;
        this.nodename = nodename;
        this.permissions = permissions;
        this.nodeDepth = nodeDepth;
        this.available = available;
    }

    public Integer getIdresource() {
        return idresource;
    }

    public void setIdresource(Integer idresource) {
        this.idresource = idresource;
    }

    public String getNodename() {
        return nodename;
    }

    public void setNodename(String nodename) {
        this.nodename = nodename;
    }

    public String getPermissions() {
        return permissions;
    }

    public void setPermissions(String permissions) {
        this.permissions = permissions;
    }

    public Integer getParentNodeId() {
        return parentNodeId;
    }

    public void setParentNodeId(Integer parentNodeId) {
        this.parentNodeId = parentNodeId;
    }

    public String getNodeUrl() {
        return nodeUrl;
    }

    public void setNodeUrl(String nodeUrl) {
        this.nodeUrl = nodeUrl;
    }

    public Integer getNodeType() {
        return nodeType;
    }

    public void setNodeType(Integer nodeType) {
        this.nodeType = nodeType;
    }

    public int getNodeDepth() {
        return nodeDepth;
    }

    public void setNodeDepth(int nodeDepth) {
        this.nodeDepth = nodeDepth;
    }

    public Integer getResourceorder() {
        return resourceorder;
    }

    public void setResourceorder(Integer resourceorder) {
        this.resourceorder = resourceorder;
    }

    public boolean getAvailable() {
        return available;
    }

    public void setAvailable(boolean available) {
        this.available = available;
    }

    @XmlTransient
    public List<RoleResource> getRoleResourceList() {
        return roleResourceList;
    }

    public void setRoleResourceList(List<RoleResource> roleResourceList) {
        this.roleResourceList = roleResourceList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idresource != null ? idresource.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Resource)) {
            return false;
        }
        Resource other = (Resource) object;
        if ((this.idresource == null && other.idresource != null) || (this.idresource != null && !this.idresource.equals(other.idresource))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.entity.Resource[ idresource=" + idresource + " ]";
    }
    
}
